package com.android.base.ui.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.WindowManager;

import com.android.base.util.DisplayUtil;
import com.example.lib_base.R;
import com.example.lib_base.databinding.LibBaseDialogGenderBinding;

/**
 * FileName: DialogGender
 * Author: admin
 * Date: 2021/11/5 16:11
 * Description:
 */
public class DialogGender extends Dialog {

    private LibBaseDialogGenderBinding genderBinding;
    private Activity activity;
    private String content1;
    private String content2;
    private ActionLister clickLister = null;

    public DialogGender(Activity a) {
        super(a, R.style.dialog_loading);
        this.activity = a;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
        genderBinding = LibBaseDialogGenderBinding.inflate(activity.getLayoutInflater());
        setContentView(genderBinding.getRoot());
        getWindow().getDecorView().setPadding(0, 0, 0, 0);
        WindowManager.LayoutParams lp = getWindow().getAttributes();
        lp.width = DisplayUtil.getScreenWidth(activity) / 5 * 4;
        getWindow().setAttributes(lp);

        if (!TextUtils.isEmpty(content1)) {
            genderBinding.tvContent1.setText(content1);
        }
        if (!TextUtils.isEmpty(content2)) {
            genderBinding.tvContent2.setText(content2);
        }

        genderBinding.tvContent1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
                if (clickLister != null) {
                    clickLister.onSuccess(DialogGender.this, 1);
                }
            }
        });
        genderBinding.tvContent2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
                if (clickLister != null) {
                    clickLister.onSuccess(DialogGender.this, 2);
                }
            }
        });
    }

    public DialogGender setContent1(String value) {
        this.content1 = value;
        return this;
    }

    public DialogGender setContent2(String value) {
        this.content2 = value;
        return this;
    }

    public DialogGender setActionLister(ActionLister lister) {
        clickLister = lister;
        return this;
    }

    public interface ActionLister {
        void onSuccess(Dialog dialog, int pos);
    }
}
